//
//  RBSearchGoodsProgressView.m
//  zhongzhenglu
//
//  Created by XL on 2022/7/12.
//

#import "RBSearchGoodsProgressView.h"
#import "RBDefine.h"
#import <UIView+YYAdd.h>
#import "UIView+RBAdd.h"
#import <UIColor+YYAdd.h>
#import "RanTool.h"

@interface RBSearchGoodsProgressView()

@property(nonatomic, strong)UILabel *doneL;
@property (nonatomic, strong) UIView *currentV;

@end

@implementation RBSearchGoodsProgressView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = [UIColor colorWithHexString:@"#FBF6F3"];
    }
    return self;
}

#pragma mark - Setter

- (void)setTitleColor:(UIColor *)titleColor {
    _titleColor = titleColor;
    self.doneL.textColor = titleColor;
}

- (void)setItemH:(CGFloat)itemH
{
    _itemH = itemH;
    [self rbSetCornerRadius:itemH/2];
    self.currentV.height = itemH;
}

- (void)setPercent:(CGFloat)percent
{
    _percent = percent;
    self.currentV.width = percent * self.itemW;
    
    NSString *title = [NSString stringWithFormat:@"已抢%.0f%%", percent*100];
    self.doneL.text = title;
}

#pragma mark - Getter

- (UILabel *)doneL
{
    if (!_doneL)
    {
        self.doneL = ({
            UILabel *view = UILabel.new;
            view.textAlignment = NSTextAlignmentLeft;
            view.font = [UIFont boldSystemFontOfSize:Zoom(11)];
            view.layer.zPosition = 3;
            view.textColor = [UIColor whiteColor];
            [self addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(Zoom(20));
                make.top.bottom.mas_equalTo(0);
                make.right.mas_equalTo(Zoom(-20));
            }];
            
            view;
        });
    }
    return _doneL;
}

- (UIView *)currentV {
    if (!_currentV) {
        self.currentV = ({
            UIView *view = UIView.new;
            view.left = 0;
            view.top = 0;
            view.backgroundColor = [UIColor colorWithHexString:@"#E83922"];
            view.layer.zPosition = 2;
            [self addSubview:view];
            view;
        });
    }
    return _currentV;
}

@end
